'' Octopilot -- Action.spin
'' (c) 2008-2009 Ben Levitt
'' http://code.google.com/p/octopilot/
''
'' Simple control object that waits for the navigation state to include NavReachedWP,
'' and pulse a pin on until NavReachedWP is no longer set.
'' This can be used to trigger a camera shutter, or anything else.
'' It can be easily changed to control a servo instead of sending a pulse.


OBJ
  config :  "Config"


VAR
  byte actionPin
  long inValsAddr
  long outValsAddr
  long defaultValsAddr
  long navStateAddr
  

PUB Start(insAddr, outsAddr, defaultsAddr, _navStateAddr)
  inValsAddr := insAddr
  outValsAddr := outsAddr
  defaultValsAddr := defaultsAddr
  navStateAddr := _navStateAddr
  dira[config#actionPinBase]~~
  dira[config#actionPinBase+1]~~
  

PUB Apply | navState
  ' Get NavState, check for NavReachedWP
  navState := BYTE[navStateAddr]
  
  if (navState & config#NavReachedWP)
    outa[config#actionPinBase] := 1
    'WORD[outValsAddr+config#gear*2] := 18_000

  if (navState & config#NavReachedWP) == 0
    outa[config#actionPinBase] := 0
    'WORD[outValsAddr+config#gear*2] := 12_000
   